package com.visutech.common.utils;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;

/**
 * Created by 程振奇 on 2018/1/25.
 */
public class PasswordUtil {

    private static final String SITE_WIDE_SECRET = MD5Util.string2MD5("hachi");
    private static final PasswordEncoder encoder = new StandardPasswordEncoder(SITE_WIDE_SECRET);

    public static String encrypt(String password) {
        return encoder.encode(password);
    }

    public static boolean match(String rawPassword, String password) {
        return encoder.matches(rawPassword, password);
    }
    public static void main(String[] args) {

        System.out.println(PasswordUtil.encrypt("test"));
        System.out.println(PasswordUtil.match("test", "0eddb5af8e6da0f41bce12bdf5252e55a8bcec1c8385da476ed16fdd38edc0b7ced76cf4d19e163d"));
    }

}
